import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ImageInfo } from './types';

/**
 * 上传图片
 *
 * @param datas
 */
export function uploadImgApi(datas: ImageInfo): AxiosPromise<any> {
  const formData = new FormData();
  formData.append('type', datas.type);
  formData.append('image', datas.image);
  return request({
    url: 'api/v1/imageupload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

/**
 * 删除图片
 *
 * @param filePath 图片完整路径
 */
export function deleteFileApi(filePath?: string) {
  return request({
    url: '/api/v1/deletefiles',
    method: 'delete',
    params: { filePath: filePath }
  });
}
